package com.tz.crm.service.impl;

import com.tz.crm.dao.PaymentDao;
import com.tz.crm.entity.Contract;
import com.tz.crm.entity.Payment;
import com.tz.crm.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 付款计划的查询保存
 */
@Service
@Transactional
public class PaymentServiceImpl extends BaseServiceImpl<Payment, String> implements PaymentService {

    @Autowired
    private PaymentDao paymentDao;

    /**
     * 有参构造
     *
     * @param paymentDao 注入的组件
     */
    @Autowired
    public PaymentServiceImpl(PaymentDao paymentDao) {
        this.paymentDao = paymentDao;
        super.setBaseDao(paymentDao);
    }

    @Override
    public void savePayment(List<Payment> payments, String contractId) {
        for (Payment p : payments) {
            Contract c = new Contract();
            c.setId(contractId);
            p.setContract(c);
            paymentDao.save(p);
        }
    }

    @Override
    public List<Payment> getByContractId(String id) {
        return paymentDao.getByContractId(id);
    }

    @Override
    public List<Payment> search(Payment payment) {
        return paymentDao.search(payment);
    }
}
